<template>
	<view>
		<scroll-view scroll-y="true" class="scroll-Y" @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll">
			<!-- 搜索框 -->
			<view class="search-wrap">
				<u-search style="width: 100%;height: 72rpx;" placeholder="搜索案例" v-model="params.keyword"
					bgColor="#F7F8FA" searchIconColor="#020202" searchIconSize="25" placeholderColor="#C8C9CC"
					:showAction="false">
				</u-search>
				<button @click="onSearch()" class="search_button">搜索</button>
			</view>
			<!-- 头部 -->
			<case-header @onTapItem="onTapItem"></case-header>
			<!-- 几个图文 -->
			<view class="case-wrap">
				<view v-for="(item, itemIndex) in caseList" :key="itemIndex" @tap="toDetail(item)" class="item">
					<view class="img-wrap">
						<image :src="item.logo" mode="widthFix"></image>
					</view>
					<view class="title">
						{{item.title==null?'':item.title}}
					</view>
				</view>
			</view>
			<view class="data-loading" v-if="loading">数据加载中...</view>
			<view class="data-loading" v-if="finished">没有更多了</view>
		</scroll-view>

		<!-- 底部导航 -->
		<u-tabbar v-model="nav_current" :list="nav_list" height="100"></u-tabbar>
	</view>


</template>

<script>
	import CaseHeader from './components/CaseHeader'
	export default {
		components: {
			CaseHeader
		},
		data() {
			return {
				loading: false,
				finished: false,
				nav_current: 1,
				params: {
					keyword: "", // 搜索关键字
					type: '', //车型
					product: '',
					color: '',
					caseType: 1,
					pageNo: 1,
					pageSize: 12
				},
				nav_list: [{
						pagePath: "/pages/index/index",
						iconPath: "/static/death/nav/home.png",
						selectedIconPath: "/static/death/home-selected.png",
						text: '首页'
					},
					{
						pagePath: "/pages/car/case",
						iconPath: "/static/death/nav/case.png",
						selectedIconPath: "/static/death/nav/case-selected.png",
						text: '案例'
					},
					{
						pagePath: "/pages/car/quote",
						iconPath: "/static/death/nav/price.png",
						selectedIconPath: "/static/death/nav/price-selected.png",
						text: '报价'
					},
					{
						pagePath: "/pages/product/product",
						iconPath: "/static/death/nav/brand.png",
						selectedIconPath: "/static/death/nav/brand-selected.png",
						text: '品牌'
					},
					{
						pagePath: "/pages/my/my",
						iconPath: "/static/death/nav/mine.png",
						selectedIconPath: "/static/death/nav/mine-selected.png",
						text: '我的'
					},
				], // 底部导航
				caseList: []
			}
		},
		onLoad() {
			this.getList();
			console.log(this.nav_current);
		},
		onReady() {

		},
		methods: {
			async onTapItem(item, itemIndex, itemParam) {
				console.log(item);
				this.params.caseType = itemIndex;
				this.params.type = itemParam.type;
				this.params.product = itemParam.product;
				this.params.color = itemParam.color;
				this.params.pageNo = 1;
				this.finished = false;
				this.getList();
			},
			toDetail(item) {
				console.log(item);
				uni.navigateTo({
					url: '/pages/car/caseDetail?id=' + item.id
				})
			},
			onSearch() {
				this.caseList = [];
				this.params.pageNo = 1;
				this.finished = false;
				this.getList();
			},
			async getList() {
				if (this.finished) return;
				this.loading = true;
				let res = await this.$api.getCarCases(this.params);
				this.loading = false;
				if (!res.success) {
					return;
				}
				const {
					current,
					pages,
					records,
					size,
					total
				} = res.result
				if (this.params.pageNo === 1) {
					this.caseList = records;
				} else {
					this.caseList = this.caseList.concat(records)
				}
				this.finished = (current * size >= total)

			},
			scroll(e) {
				console.log(e)
			},
			upper(e) {
				console.log(e)
			},
			lower(e) {
				this.params.pageNo++
				this.getList();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scroll-Y {
		height: calc(100vh - 110rpx);
		padding-bottom: 10rpx;
		background: #F5F5F5;
	}

	.search-wrap {
		height: 102rpx;
		width: 100%;
		display: flex;
		align-items: center;
		background-color: #FFFFFF;
		margin-top: 2rpx;
		padding: 20rpx 32rpx 12rpx 32rpx;

		// margin-bottom: 10rpx;
		.search_button {
			position: absolute;
			z-index: 900;
			right: 32rpx;
			height: 64rpx;
			width: 112rpx;
			border-radius: 1290rpx 1290rpx 1290rpx 1290rpx;
			background: #000000;
			font-family: PingFang SC;
			font-weight: 400;
			font-size: 26rpx;
			color: #FBD62B;
			white-space: nowrap;

			&:active {
				color: #877216;
			}
		}
	}

	.case-wrap {
		display: flex;
		align-content: flex-start;
		padding: 0rpx 10rpx 0rpx 20rpx;
		flex-wrap: wrap;
		background-color: #F5F5F5;
		margin: 13rpx;
		// margin-top: 0;
		min-height: 600rpx;

		.item {
			// width: 48%;
			width: 336rpx;
			// margin-right: 12rpx;
			background-color: #F5F5F5;
			// margin-bottom: 10rpx;
			margin:20rpx 12rpx 10rpx 0rpx ;
		}

		.img-wrap {
			margin: 0rpx 0rpx 10rpx 0rpx;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			height: 252rpx;
			overflow: hidden;
		}

		.title {
			font-size: 24rpx;
			width: 100%;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			// margin-top: 10rpx;
			padding: 0rpx 0rpx;
		}
	}

	.data-loading {
		text-align: center;
		color: gray;
		font-size: 24rpx;
		background-color: #F5F5F5;
	}
</style>